** Loading data - generated in dofile: data05
use "$data\minwage_data5_estimation_2012_2015.dta", clear
keep if inrange(tline,-24,24) & apprentice == 0 // 49 event-month oberservation window & excluding apprentices

** Merging information on gender on to the estimation data
ge female = .
forval t = 2012/2015{
	merge m:1 pnr using "$data\bef`t'.dta", keep(matched) keepus(koen) nogen
	replace female = koen == 2 if aar == `t'
	drop koen
}
	replace female = female * 100 // Female dummy eq to 100 for females

** Merging information on school GPA and HS enrollment status:
**  from dofile data6
merge m:1 pnr using  "$data\minwage_data6_stdgpa.dta", nogen keep(match master) 
merge m:1 pnr using  "$data\minwage_data6_ongoing_edu.dta", nogen keep(match master) keepus(igfsp)

ge t_hs = 1 if inrange(igfsp, 20000000, 30000000) // HS indicator codes
bysort pnr: egen D_highschool =max(t_hs)
replace D_highschool = 0 if D_highschool ==. 
replace D_highschool = D_highschool * 100 // HS dummy eq 1 if enrolled in HS
drop t_hs

** Merging information on parental income rank and region from dofile data7
merge m:1 pnr using  "$data\parental_income_ptiles10.dta", nogen keep(match master) keepus(avg_p_earn_rank region)

ge CPH = region == 84 // CPH region code
replace CPH = CPH * 100 // CPH dummy eq 1 if living in CPH

	** Collapsing to get observations count by event time
	collapse (count) observations = pnr (mean) female (mean) CPH (mean) D_highschool ///
										(mean) ptile (mean) avg_p_earn_rank , by(tline)
	
	egen tot_obs = sum(observations) // total observations	
	ge tline_frac = ( observations / tot_obs ) * 100 // percent

** Figure A.8: Additional Tests of RD Validity: McCrary(2008) and Continuity of Observables
** (a) Density of the Running Variable
two connected tline_frac tline, color(black) msize(large) graphregion(color(white)) msize(large) ///
		yti("Percent") ylabel(0(1)10) ///
		graphregion(color(white) margin(vsmall)) ///
		xline(-12, lcolor(grey)) xline(0, lcolor(grey)) xline(12, lcolor(grey)) ///
		xti("Month relative to 18th birthday") xlabel(-24(2)24) legend(off) scale(.85)	
		graph export "$out\Apndx_Figure8A_excl_apprentices_obs_pct_tline_dofile_descrp05.png", width(800) height(600) replace
		
** (b) Fraction Female
two connected female tline, color(black) msize(large) graphregion(color(white)) msize(large) ///
		yti("Percent") ylabel(0(20)100) ///
		graphregion(color(white) margin(vsmall)) ///
		xline(-12, lcolor(grey)) xline(0, lcolor(grey)) xline(12, lcolor(grey)) ///
		xti("Month relative to 18th birthday") xlabel(-24(2)24) legend(off) scale(.85)	
		graph export "$out\Apndx_Figure8B_excl_apprentices_female_tline_dofile_descrp05.png", width(800) height(600) replace
		
** (c) Fraction Living in Capital City (Copenhagen) Area
two connected CPH tline, color(black) msize(large) graphregion(color(white)) msize(large) ///
		yti("Percent") ylabel(0(10)50) ///
		graphregion(color(white) margin(vsmall)) ///
		xline(-12, lcolor(grey)) xline(0, lcolor(grey)) xline(12, lcolor(grey)) ///
		xti("Month relative to 18th birthday") xlabel(-24(2)24) legend(off) scale(.85)	
		graph export "$out\Apndx_Figure8C_excl_apprentices_CPH_tline_dofile_descrp05.png", width(800) height(600) replace

** (d) Fraction Enrolled in High School
two connected D_highschool tline, color(black) msize(large) graphregion(color(white)) msize(large) ///
		yti("Percent") ylabel(0(20)100) ///
		graphregion(color(white) margin(vsmall)) ///
		xline(-12, lcolor(grey)) xline(0, lcolor(grey)) xline(12, lcolor(grey)) ///
		xti("Month relative to 18th birthday") xlabel(-24(2)24) legend(off) scale(.85)	
		graph export "$out\Apndx_Figure8D_excl_apprentices_highschool_tline_dofile_descrp05.png", width(800) height(600) replace
		
** (e) Grade Point Average Decile
two connected ptile tline, color(black) msize(large) graphregion(color(white)) msize(large) ///
		yti("Percent") ylabel(0(1)10) ///
		graphregion(color(white) margin(vsmall)) ///
		xline(-12, lcolor(grey)) xline(0, lcolor(grey)) xline(12, lcolor(grey)) ///
		xti("Month relative to 18th birthday") xlabel(-24(2)24) legend(off) scale(.85)	
		graph export "$out\Apndx_Figure8E_excl_apprentices_GPA_tline_dofile_descrp05.png", width(800) height(600) replace
		
** (f) Parental Earnings Decile
two connected avg_p_earn_rank tline, color(black) msize(large) graphregion(color(white)) msize(large) ///
		yti("Percent") ylabel(0(1)10) ///
		graphregion(color(white) margin(vsmall)) ///
		xline(-12, lcolor(grey)) xline(0, lcolor(grey)) xline(12, lcolor(grey)) ///
		xti("Month relative to 18th birthday") xlabel(-24(2)24) legend(off) scale(.85)	
		graph export "$out\Apndx_Figure8F_excl_apprentices_parental_earn_decile_tline_dofile_descrp05.png", width(800) height(600) replace
